package top.xxyu.resume.demo;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xxyu.web.login.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class DemoService {

    @Autowired
    private MybatisDao mybatisDao;


    public Map<String, Object> find(){
        //分页插件: 查询第1页，每页10行
        Page<User> page = PageHelper.startPage(1, 10);
        List<Map> list = mybatisDao.findAll();
        //数据表的总行数
        long total = page.getTotal();
        //分页查询结果的总行数
        int size = page.size();
        //第一个User对象，参考list，序号0是第一个元素，依此类推
        page.get(0);
        Map<String, Object> result = new HashMap<>();
        result.put("datas", list);
        result.put("total", total);
        result.put("size", size);
        return result;
    }
}
